package com.sunop.discussion.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.sunop.discussion.model.Discussion;
import com.sunop.discussion.model.DiscussionPageQueryDTO;
import com.sunop.discussion.model.DiscussionReplyPO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hutao666123
 * @since 2025-03-22
 */
@Mapper
public interface DiscussionMapper extends BaseMapper<Discussion> {


    Page<Discussion> pageQuery(DiscussionPageQueryDTO discussionPageQueryDTO);

    @Select("select uid from discussion where id = #{id}")
    int selectCidById(Integer id);

    @Insert("insert into discussion_reply (uid, content, to_cid, to_name, author, avatar, role) values (#{uid}, #{content}, #{toCid}, #{toName}, #{author}, #{avatar}, #{role})")
    void insertReply(DiscussionReplyPO discussionReplyPO);

    Page<DiscussionReplyPO> replyPageQuery(int cid, DiscussionPageQueryDTO discussionPageQueryDTO);

    @Select("select uid from discussion_reply where id = #{id}")
    int selectReplyCidById(Integer id);

    @Delete("delete from discussion_reply where id = #{id}")
    void deleteReplyById(Integer id);
}
